import com.modestmaps.InteractiveMap;
import processing.core.PFont;

public class Map {


	float delay =0;
	int widthHeight ;
	float circleWidthHeight;

	InteractiveMap map;
	PFont font;
	boolean gui = true;


	public void draw(float dt) {
		GLOBAL.processing.background(0);
		// see if the arrow keys or +/- keys are pressed:
		// (also check space and z, to reset or round zoom levels)
		if (GLOBAL.processing.keyPressed) {
			if (GLOBAL.processing.key == GLOBAL.processing.CODED) {
				if (GLOBAL.processing.keyCode == GLOBAL.processing.LEFT) {
					//if((map.tx + 20.0/map.sc)<-22 )
					map.tx += 20.0/map.sc;
				}
				else if (GLOBAL.processing.keyCode == GLOBAL.processing.RIGHT) {
					//if((map.tx - 20.0/map.sc)> -242)
					map.tx -= 20.0/map.sc;
				}
				else if (GLOBAL.processing.keyCode == GLOBAL.processing.UP) {
					//if((map.ty + 20.0/map.sc)< -12)
					map.ty += 20.0/map.sc;
				}
				else if (GLOBAL.processing.keyCode == GLOBAL.processing.DOWN) {
					//if((map.ty - 20.0/map.sc)> -240)
					map.ty -= 20.0/map.sc;
				}
			}  
			else if (GLOBAL.processing.key == '+' || GLOBAL.processing.key == '=') {
				if(map.sc*1.05<22){
					map.sc *= 1.05;
				}

			}
			else if (GLOBAL.processing.key == '_' || GLOBAL.processing.key == '-' && map.sc > 2) {
				if((map.sc * 1.0/1.05)>5){
					map.sc *= 1.0/1.05;
				}
			}
		}

		// draw the map:
		map.draw();
		// (that's it! really... everything else is interactions now)


		// draw all the buttons and check for mouse-over
		boolean hand = false;
		//  if (gui) {
		//    for (int i = 0; i < buttons.length; i++) {
		//      buttons[i].draw();
		//      hand = hand || buttons[i].mouseOver();
		//    }
		//  }

		// if we're over a button, use the finger pointer
		// otherwise use the cross
		// (I wish Java had the open/closed hand for "move" cursors)

		GLOBAL.processing.stroke(0,0,0);

	}

	public void keyReleased() {
		if (GLOBAL.processing.key == 'g' || GLOBAL.processing.key == 'G') {
			gui = !gui;
		}
		else if (GLOBAL.processing.key == 's' || GLOBAL.processing.key == 'S') {
			GLOBAL.processing.save("modest-maps-app.png");
		}
		else if (GLOBAL.processing.key == 'z' || GLOBAL.processing.key == 'Z') {
			map.sc = GLOBAL.processing.pow(2, map.getZoom());
		}
	}


	public void mouseDragged() {
		map.mouseDragged(); 
	}
	
	// zoom in or out:
	void mouseWheel(int delta) {
		if (delta < 0) {
			if((map.sc * 1.05)<22){
			map.sc *= 1.05;
			}
		}
		else if (delta > 0) {
			if((map.sc * 1.0/1.05)>5){
				map.sc *= 1.0/1.05;
			}
		}
	}

	public void mouseClicked() {
	}


}